package org.example.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.io.Resource; // 使用这个 Resource 而非 Tomcat 的 Resource
import org.springframework.stereotype.Component;
import org.springframework.util.FileCopyUtils;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;

@Component
@ConfigurationProperties(prefix = "ai.assistant")
public class AssistantProperties {

    // 正确的 Resource 类型注入
    @Value("${ai.assistant.prompt-file:classpath:develop-assistant.md}")
    private Resource promptFile; // 使用 org.springframework.core.io.Resource

    public String getSystemPrompt() {
        try (Reader reader = new InputStreamReader(promptFile.getInputStream(), StandardCharsets.UTF_8)) {
            return FileCopyUtils.copyToString(reader);
        } catch (IOException e) {
            throw new RuntimeException("无法加载助手提示词文件", e);
        }
    }
}